import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.util.HashSet;
import java.util.Set;

public class JedisClusterHW {

    JedisCluster jedis = null;



    @Before
    public void conn() {
        Set<HostAndPort> nodes = new HashSet<HostAndPort>();
        nodes.add(new HostAndPort("192.168.15.2", 8001));
        nodes.add(new HostAndPort("192.168.15.2", 8002));
        nodes.add(new HostAndPort("192.168.15.2", 8003));
        nodes.add(new HostAndPort("192.168.15.2", 8004));
        nodes.add(new HostAndPort("192.168.15.2", 8005));
        nodes.add(new HostAndPort("192.168.15.2", 8006));
        nodes.add(new HostAndPort("192.168.15.2", 8007));
        nodes.add(new HostAndPort("192.168.15.2", 8008));
        jedis = new JedisCluster(nodes);
    }


    @Test
    public void insertAndGet() {

        // 添加一条数据
        jedis.set("username", "陈润东");
        // 获取一条数据
        String username = jedis.get("username");
        System.out.println("用户名：" + username);

        // 删除
        jedis.del("username");
    }
}
